package com.zheng1.envii.room.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.zheng1.envii.room.dao.EnvIIBleDeviceDataDao
import com.zheng1.envii.room.entity.EnvIIBleDeviceDataEntity

@Database(entities = [EnvIIBleDeviceDataEntity::class], version = 1, exportSchema = false)
public abstract class EnvIIBleDeviceDatabase : RoomDatabase() {

    abstract fun envIIBleDeviceDataDao(): EnvIIBleDeviceDataDao

    companion object {
        @Volatile
        private var INSTANCE: EnvIIBleDeviceDatabase? = null

        fun getInstance(context: Context): EnvIIBleDeviceDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    EnvIIBleDeviceDatabase::class.java,
                    "envii_ble_device_data_database"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }

}